<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        height: 300px;
        width: 200px;
      }
      table {
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div class="box" id="app">
      <h2>远强礼物清单</h2>
      <table cellspacing="0" border="1">
        <tr>
          <th>礼物</th>
          <th>数量</th>
        </tr>
        <tr v-for="(item,index) in list " key="item.id">
          <td>{{item.name}}</td>
          <td>{{item.num}}</td>
        </tr>
      </table>
      <p>礼物总数:{{totalCount}}</p>
    </div>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          list: [
            { id: 1, name: "小说", num: 2 },
            { id: 2, name: "篮球", num: 5 },
            { id: 3, name: "演唱会门票", num: 1 },
          ],
        },
        computed: {
          totalCount() {
            return (total = this.list.reduce((sum, item) => sum + item.num, 0));
          },
        },
      });
    </script>
  </body>
</html>
